package controller.admin;

import com.jfinal.aop.Inject;
import com.jfinal.kit.Kv;

import controller.admin.base.BaseAdminController;
import model.Role;
import model.User;
import service.UserService;

public class AdminUserController extends BaseAdminController {
    @Inject
    private UserService userService;
    
    public void list() {
    	Kv map = getParamKv();
        Integer pageNum = getParaToInt("pageNumber", 1);
        Integer pageSize = getParaToInt("pageSize", 10);
        renderJson("page", userService.getPage(map , pageNum, pageSize));
    }
    
    public void info() {
    	 User user = User.dao.findById(getParaToInt("id"));
         set("data", user);
         set("roleList", Role.dao.findAll());
         renderJson();
	}
    
    public void save() {
    	User user = getModel(User.class,"x");
        renderJson(userService.saveUser(user));
	}
    
    public void delete(){
        Long id = getParaToLong("id");
        renderJson(userService.delete(id));
    }
    
    public void changeStatus() {
		boolean isUsable = getBoolean("isUsable",true);
		Long id = getParaToLong("id");
		renderJson(userService.changeStatus(id , isUsable));
	}

}
